import java.io.*;
import java.io.InputStreamReader;
import java.lang.Runtime;
import javax.servlet.*;
import javax.servlet.http.*;

public class loadbalancer extends HttpServlet {
  
  final int max = 5;
  int index = 0;
  String availableIps[] = {"10.0.0.10", "10.0.0.11", "10.0.0.12", "10.0.0.13", "10.0.0.14"};

  public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
  {
    PrintWriter out = response.getWriter();
    Process process;
    try{
      process = Runtime.getRuntime().exec("free");
      process.waitFor();
      if(process.exitValue() == 0) {
        try {
         BufferedReader in = new BufferedReader(
         new InputStreamReader(process.getInputStream()));
         String line = null;
         while((line = in.readLine()) != null) {
            out.println(line);
         }
      }catch(Exception e) {
        
      }
      }
      else out.println("\nCommand failed.");
    }
    catch (Exception e) {
      out.println("\n" + e.toString());
    }
    response.setContentType("text/html");
    
    out.println("\n" + availableIps[(index++) % max]);
  }

  public static void main (String[] args) {
    
  }

}
